% TEST_ID: LANG-EXPAND-0044
% CATEGORY: language/struct
% 测试结构体的构造

function test_struct_construct
    A = struct('field1', 1, 'field2', 2);
    B.field1 = 1;
    B.field2 = 2;
    assert(isequal(A, B)); % Test basic struct creation
    assert(isequal(class(A), 'struct')); % Ensure class is struct

    assert(isfield(A, 'field1')); % Check if field exists
    assert(isfield(A, 'field2')); % Check if another field exists

    assert(~isfield(A, 'field3')); % Check non-existent field

    assert(isequal(A.field1, 1)); % Access field value
    assert(isequal(A.field2, 2)); % Access another field value

    assert(isequal(fieldnames(A), {'field1'; 'field2'})); % Check field names
    assert(isequal(numel(A), 1)); % Check number of elements in struct
    assert(isequal(size(A), [1 1])); % Check size of struct

    name1 = 'field1';
    C.(name1) = 10; % Dynamic field name assignment
    assert(isequal(C.field1, 10)); % Check dynamic field assignment
end

